package com.example.xiaozu.activity;


import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.xiaozu.R;

public class RegisterActivity extends AppCompatActivity {

    private EditText etUsername,etPassword;
    private Button btnRegister;
    private boolean username;
    private boolean password;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        etUsername = findViewById(R.id.et_username);
        etPassword = findViewById(R.id.et_password);
        btnRegister = findViewById(R.id.btn_register);

        // 修改注册逻辑
        btnRegister.setOnClickListener(v -> {
            String username = etUsername.getText().toString().trim();
            String password = etPassword.getText().toString().trim();

            if (username.isEmpty() ||  password.isEmpty()) {
                Toast.makeText(this, "请填写完整信息", Toast.LENGTH_SHORT).show();
                return;
            }

            SharedPreferences preferences = getSharedPreferences("users", MODE_PRIVATE);
            SharedPreferences.Editor editor = preferences.edit();
            editor.putString(username + "_username", username);
            editor.putString(username + "_password", password);
            editor.apply();

            Toast.makeText(this, "注册成功", Toast.LENGTH_SHORT).show();
            finish();
        });
    }
}
